//
//  JYTCoachHandler.m
//  JYT_IOS
//
//  Created by nxa-tankeke on 17/1/11.
//  Copyright © 2017年 nxa-yuanguoxiang. All rights reserved.
//

#import "JYTCoachHandler.h"

@implementation JYTCoachHandler
+ (JYTCoachHandler *) shared
{
    static dispatch_once_t onceToken;
    static JYTCoachHandler *coachHandler;
    dispatch_once(&onceToken, ^{
        coachHandler = [[JYTCoachHandler alloc] init];
    });
    return coachHandler;
}


- (void) getSchoolCoachWithParam:(NSDictionary *)params WithHandler:(void (^)(NSArray *coaches, NSString *pageNo)) handler
{
    JYTHttpClient *client = [JYTHttpClient sharedInstance];
    
    BOOL isUsedOffLine = [[JYTUserManager shared] isUsedOffLine];
    if (!isUsedOffLine) {
        
        client.urlType = userCityUrl;
    } else {
        client.urlType = userCenterUrl;
    }
    
    client.finishCallbackHandler = ^(id result, NSString *code, NSString *msg) {
        
        NSArray *arr = result[@"data"];
        NSNumber *number = result[@"PageCount"];
        
        NSString *pageNo = [NSString stringWithFormat:@"%@", number];
        
        NSArray *coachArr = [JYTAppointModel mj_objectArrayWithKeyValuesArray:arr];
        
        handler(coachArr, pageNo);
    };
    
    client.errorCallbackHandler = ^(NSString * code, NSString * msg) {
        handler(@[], nil);
    };
    
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setDictionary:params];
    
    //请求 CommandCode
    [param setObject:@"GetCoach" forKey:@"CommandCode"];
    
    [client post:@"GetDataInfo" withParam:param];
}


@end
